package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.MatteBorder;

import model.User;
import javax.swing.JCheckBox;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.Component;

public class LoginDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textFieldUsername;
	private JTextField passwordField;

	/**
	 * Create the dialog.
	 * @param password 
	 * @param username 
	 */
	public LoginDialog() {
		setBounds(100, 100, 306, 181);
		setTitle("Login/Register dialog");
		setLocationRelativeTo(MainFrame.getInstance());
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.X_AXIS));
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setModal(true);
		JPanel panel = new JPanel();
		contentPanel.add(panel);
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		
		JPanel panel_1 = new JPanel();
		panel.add(panel_1);
		JLabel lblUsername = new JLabel("Username:");
		panel_1.add(lblUsername);
		textFieldUsername = new JTextField();
		panel_1.add(textFieldUsername);
		textFieldUsername.setText("medo maddalena");
		textFieldUsername.setColumns(10);
		JPanel panel2 = new JPanel();
		panel.add(panel2);
		JLabel lblPassword = new JLabel("Password:");
		panel2.add(lblPassword);
		passwordField = new JTextField();
		passwordField.setColumns(10);
		panel2.add(passwordField);
		passwordField.setText("pass");
		
		final JCheckBox chckbxRegister = new JCheckBox("Register");

		panel.add(chckbxRegister);

		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
		JButton okButton = new JButton("OK");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstance().setLoginUsername(textFieldUsername.getText().trim());
				MainFrame.getInstance().setLoginPassword(passwordField.getText().trim());
				MainFrame.getInstance().setRegisterUser(chckbxRegister.isSelected());
				dispose();
				}
		});
		buttonPane.add(okButton);
		getRootPane().setDefaultButton(okButton);
		JButton cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		//cancelButton.setActionCommand("Cancel");
		buttonPane.add(cancelButton);
	}

	public JTextField getTextFieldUsername() {
		return textFieldUsername;
	}

	public void setTextFieldUsername(JTextField textFieldUsername) {
		this.textFieldUsername = textFieldUsername;
	}

	public JTextField getPasswordField() {
		return passwordField;
	}

	public void setPasswordField(JPasswordField passwordField) {
		this.passwordField = passwordField;
	}
	
	

}
